<?php 
require_once '../config.php';
require_once('../functions.php'); ?>
<?php if(!isset($_SESSION['loggedin'])) { 
	header('Location:'. SITE_URL . 'admin/?notloggedin');
 } ?>
<html>
<head>
	<title>Dashboard</title>
	<link href="../css/bootstrap.min.css" type="text/css" rel="stylesheet" />
	<link href="../css/style.css" type="text/css" rel="stylesheet" />
	<script src="../js/jquery-1.11.1.min.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			function toTitleCase(str) {
				return str.replace(/(?:^|\s)\w/g, function(match) {
					return match.toUpperCase();
				});
			}
			$('.contest_action').click(function()
			{
				var self = $(this);
				var id = $(this).data('id');
				var action = $(this).data('action');
				var postdata = {'id':id, 'action': action}
				$.ajax({
					type:'get',
					url:'ajax.php',
					data:postdata,
					success:function(result)
					{	
						var res = result.split('-');						
						if(res[0] == 'success')
						{							
							self.html(toTitleCase(res[1]));
							self.data('action',res[1]);
						}
						
					}
				});
			
			})		
		});	
	</script>
</head>
<body>
<div class="container">
	<div class="row">
	<div class="col-lg-2 col-lg-offset-5 col-md-2 col-md-offset-5 col-sm-2 col-sm-offset-5 col-xs-2 col-xs-offset-5">
		<img class="width-100" src="../img/logo.png">
	</div>
	<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
	<a id="logout_dash" class="btn btn-default btn-lg dropdown-toggle" href="<?=SITE_URL?>/admin/?logout">LOGOUT</a>
	</div>
		<div class="col-lg-12 col-md-12 cool-sm-12 col-xs-12">
			<?php if(isset($_GET['admin_success']) && $_GET['admin_success'] == 1 ) { ?>
				<div class="bg-success" style="padding:10px;margin-top:20px;">Updated Successfully.</div>
			<?php } ?>
			<h2>Contest Entries</h2>
			<br>
			<table class="table table_dashboard table-hover">
				<tr class="table_dashboard">
					<th>ID</th>
					<th>Name</th>
					<th>Phone</th>
					<th>Email</th>
					<th>Message</th>
					<th>Image</th>
					<th>Action</th>
				</tr>
				<?php $contests = get_contest_details(); ?>
				<?php foreach($contests as $contest) { ?>
					<tr>
						<td><?=$contest['id']?></td>
						<td><?=$contest['name']?></td>
						<td><?=$contest['phone']?></td>
						<td><?=$contest['email']?></td>
						<td><?=$contest['message']?></td>
						<td><a href="<?php echo SITE_URL.'upload/'.$contest['picture']; ?>" target="_blank">Show</a></td>
						<td><?php if(empty($contest['approved'])) echo '<a class="contest_action" data-id="'.$contest['id'].'" data-action="approve" href="javascript:void(0);">Approve</a>'; else echo '<a class="contest_action" data-id="'.$contest['id'].'" data-action="unapprove" href="javascript:void(0);">Unapprove</a>'; ?></td>
					</tr>
			<?php } ?>
			</table>
		</div>
	</div>
</div>
</body>
</html>
